<div class="modal fade" id="edit_address" tabindex="-1" role="dialog" >
    <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form class="form-ajax" id="form" action=""
                      method="post" autocomplete="off">
                    <input type="hidden" name="receiver[orders_id]" id="order_id" value="">
                    <input type="hidden" name="receiver[order_no]" id="order_no" value="">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="exampleModalLabel">修改收货人信息</h4>
                        </div>

                        <div class="modal-body">
                            <div class="form-group">
                                <label for="message-text" class="control-label">收货人姓名:</label>
                                <input type="text" name="receiver[receiver_name]"  id="receiver_name" class="form-control " placeholder="" value="" required/>
                            </div>

                            <div class="form-group">
                                <label for="message-text" class="control-label">收货人电话:</label>
                                <input type="text" name="receiver[receiver_tel]" id="receiver_tel" class="form-control " placeholder="" value="" required/>
                            </div>

                            <div class="form-group">
                                <label for="message-text" class="control-label">收货人详细地址:</label>
                                <input type="text" name="receiver[receiver_address]" id="receiver_address"  class="form-control " readonly placeholder="" value="" required/>
                            </div>
                            <input type="hidden" name="receiver[old_address]" id="old_address"  class="form-control "  placeholder="" value="" required/>

                            <p id="edit2">修改收货人详细地址</p>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal" >关闭</button>
                            <button type="button" id="sub"  class="btn btn-primary">提交</button>
                        </div>
                    </div>
                </form>
            </div>
    </div>
</div>
<script>
    $("#edit_address").on("hidden.bs.modal", function() {
        $("#receiver_address").attr('readonly','readonly');
    });

    $("#edit2").click(function () {
        var t =  $(this).text();
        if(t == '修改收货人详细地址'){
            $("#receiver_address").removeAttr('readonly');
            $(this).text('保存收货人地址')
        }else{
            $("#receiver_address").attr('readonly','readonly');
            $(this).text('修改收货人详细地址')
        }

    });
    function show_data(id,order_no,receiver_name,receiver_tel,receiver_address){
        $("#order_id").val(id);
        if(receiver_name && receiver_tel && receiver_address){
            $("#receiver_name").val(receiver_name);
            $("#receiver_tel").val(receiver_tel);
            $("#receiver_address").val(receiver_address);
            $("#old_address").val(receiver_address);
        }
    }

    $("#sub").click(function () {
       var t = $("#receiver_tel").val().trim();
       var receiver_name = $("#receiver_name").val().trim();
       var receiver_address = $("#receiver_address").val().trim();
       if(!receiver_name || !receiver_address){
           alert("信息不完整");
           return false;
       }
        if(t.length == 11){
            $.ajax({
                url:"?md=shop&cl=shop&at=edit_address",
                type:"post",
                data:$("#form").serialize(),
                dataType:"json",
                success:function (d) {
                    if(d.status == 1){
                        alert(d.msg);
                        location.reload();
                    }else{
                        alert(d.msg);
                    }
                }
            })
        }else{
            alert('请输入正确的手机号');
        }

    });

    // 20191226 “龙” 确认只要 判断11位即可
    function checkPhone(t){
        if(!(/^1[3-9]\d{9}$/.test(t))){
            return false;
        }else{
            return true;
        }
    }


</script>